
package com.google.code.sms.android.service;

import com.google.code.sms.android.domain.Version;

/**
 * Thrown if the REST API version implemented by the server is too old.
 *
 * @author Sindre Mehus
 * @version $Id: ServerTooOldException.java 2537 2011-11-08 14:14:14Z sindre_mehus $
 */
public class ServerTooOldException extends Exception {

    private final String text;
    private final Version serverVersion;
    private final Version requiredVersion;

    public ServerTooOldException(String text, Version serverVersion, Version requiredVersion) {
        this.text = text;
        this.serverVersion = serverVersion;
        this.requiredVersion = requiredVersion;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        if (text != null) {
            builder.append(text).append(" ");
        }
        builder.append("Server API version too old. ");
        builder.append("Requires ").append(requiredVersion).append(" but is ").append(serverVersion).append(".");
        return builder.toString();
    }
}
